export default {
    data: {
        offset: 0,
        loading: true,
        refreshing: false,
        loadMore: false,
        loadMoreAble: false
    },
    methods: {
        onRefresh() {
            if (this.refreshing || this.loadMore || this.loading) {
                return false;
            }
            this.refreshing = true;
            this.offset = 0;
            this.fetchData();
        },
        onEndReached() {
            if (this.refreshing || this.loadMore || this.loading) {
                return false;
            }

            if (!this.loadMoreAble) {
                return false;
            }

            this.loadMore = true;
            this.offset += this.pageSize;
            this.fetchData();
        },
        endLoad() {
            this.loading = false;
            this.refreshing = false;
            this.loadMore = false;
            wx.stopPullDownRefresh();
        }
    },
    // 监听用户下拉动作
    onPullDownRefresh() {
        this.onRefresh();
    },

    // 页面上拉触底事件的处理函数
    onReachBottom() {
        this.onEndReached();
    }
};
